<?php
header("Content-Type:application/json;charset=UTF-8");

$connt = mysqli_connect('localhost','root','root','admin');
if(!$connt)
{
    echo json_encode(['code'=>0,'msg'=>'连接失败']);
}
$sql = 'SELECT department.name,count(*) as total
FROM `staff` join department
on staff.dep_id = department.id
GROUP BY dep_id';
$query = mysqli_query($connt,$sql);
$data = mysqli_fetch_all($query,MYSQLI_ASSOC);

$sql1 = 'SELECT COUNT(sex) as value,sex as name from staff GROUP BY sex';
$query1 = mysqli_query($connt,$sql1);
$res = mysqli_fetch_all($query1,MYSQLI_ASSOC);

$xData = [];
$yData = [];
    foreach ($data as $val)
    {
        $xData[] = $val['name'];
        $yData[] = $val['total'];
    }
    if($data && $res)
    {
        echo json_encode(['code'=>1,'msg'=>'返回数据','data'=>[
            'x'=>$xData,
            'y'=>$yData,
            'bt'=>$res
        ]]);
    }




